package dao;

import domain.Student;

import java.util.ArrayList;

public class StudentDao {
    private static ArrayList<Student> list= new ArrayList<>();
    public void addStudent(Student student) {
        list.add(student);
    }
    public ArrayList<Student> find() {
        return list;
    }

    public void delete(String sid) {
        int index = getIndex(sid);
        list.remove(index);
    }
    public int getIndex(String sid){
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            if(student.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }

    public void update(String sid, Student student) {
        int index = getIndex(sid);
        list.set(index,student);
    }
}
